package inno.specificFitness;

import java.util.Random;

import inno.data.DataReaderSingelton;
import inno.treeRepro.Chromosome;

public class DummyFitness implements Fitness{
	private DataReaderSingelton myData;
	public DummyFitness(){
		myData = DataReaderSingelton.getInstance();
	}
	public Double doFitness(Chromosome subject){
		String stockName = subject.getStockFigure();
		int[] bumps = {5,10,15,25,50,75,100,125,150,175};
		Random rand = new Random();
		int dayFactorIndex = rand.nextInt(10);
		int myDayFactorBump = bumps[dayFactorIndex];
		// create the range of time from which to choose the day to check with
		int days = myData.getDaysSum(stockName)-myDayFactorBump;
		int randomDay = rand.nextInt(days);
		Double predictedVal = Math.abs(subject.getPredictedVal(myDayFactorBump,randomDay));
		//Double realVal = myData.getClosingPrice(stockName, randomDay+myDayFactorBump);
		Double realVal = myData.getClosingPrice(stockName, randomDay+myDayFactorBump);
		Double normalizedDiference = 1-Math.abs(predictedVal-realVal)/(predictedVal+realVal);
		if (Double.isNaN(normalizedDiference) || Double.isInfinite(normalizedDiference))
		{
			return 0.0;
		}
		// in order to prevent overfitting
		if (1.0==normalizedDiference){
			return 0.95;
		}
		return normalizedDiference;
	}

}
